const pageStack = getCurrentPages()
console.log(pageStack)
Page({
  onLoad() {
    this.setData({ ...getApp().userProfile })
    console.log(1123)
  },
  // 选择头像
  getUserAvatar(ev) {
    console.log(ev)
    wx.uploadFile({
      filePath: ev.detail.avatarUrl,
      name: 'file',
      url: wx.http.baseURL + '/upload',
      header: { Authorization: 'Bearer ' + getApp().token },
      formData: { type: 'avatar' },
      success: (result) => {
        const data = JSON.parse(result.data)
        if (data.code !== 10000) return wx.utils.toast('上传头像失败!')
        pageStack[0].setData({ avatar: data.data.url })
        this.setData({
          avatar: data.data.url,
        })
        getApp().userProfile.avatar = data.data.url
      },
    })
  },
  // 设置名字
  getUserName(ev) {
    const nickName = ev.detail.value
    wx.http.put('/userInfo', { nickName })
    pageStack[0].setData({ nickName })
    getApp().userProfile.nickName = nickName
  },
})
